home *** CD-ROM | disk | FTP | other *** search
- #ifndef MSC
-
- /* Non-MSC Version */
-
- #if (defined(M_I86CM) || defined(M_I86LM) || defined(M_I86HM))
-
- /* NOTE: These procedures should only be used for
- large data model programs (i.e., Compact, Large, Huge) */
-
- #include <stddef.h>
- #include <dos.h>
- #include "alloc.h"
-
- extern ATABLE AllocationTable [] ; /* Provide storage for block pointers */
- extern SUNIT NEntry ; /* Number of table entries */
-
- void ReduceAllocation ( CompressLastBlock )
-
- int CompressLastBlock ; /* Compress last block flag */
-
- /*
- +---------------------------------------+
- | |
- | This procedure attempts to reduce |
- | the current memory allocation to the |
- | minimum required by freeing segments |
- | which are entirely empty back to |
- | the system. |
- | |
- | If 'CompressLastBlock' flag is set, |
- | the memory allocation for the last |
- | block is reduced to the minimum |
- | (i.e., maximum compression). |
- | |
- +---------------------------------------+
- */
-
- {
- HEADER *Header ;
- SUNIT *bptr ;
- SUNIT offset ;
- SUNIT noffset;
- SUNIT bsize ;
- int i ;
- void CollapseFreeBlocks () ;
- void FreeEmptyBlocks () ;
-
-
- if ( NEntry > 0 ) {
- for ( i = 0 ; i < NEntry ; i++ )
- CollapseFreeBlocks ( AllocationTable [i].Header ) ;
- FreeEmptyBlocks ( AllocationTable [NEntry-1].Header ) ;
- if ( NEntry > 0 && CompressLastBlock ) {
-
- /* Find last block in allocation */
-
- Header = AllocationTable [NEntry-1].Header ;
- noffset = HSIZE ;
- while ( noffset < Header->BytesUsed ) {
- offset = noffset ;
- bptr = (SUNIT *) Header + offset/SSIZE ;
- bsize = *bptr & ~FREE ;
- noffset += bsize + SSIZE ;
- } ;
- if ( (*bptr & FREE ) && ( bsize + SSIZE ) >= NALLOC ) {
- bsize = Header->BytesUsed - bsize - SSIZE ;
- noffset = NALLOC *( (bsize-1)/NALLOC+1) ;
- if (_dos_setblock ( noffset/NALLOC, FP_SEG (Header), &i ) != 0 )
- return ;
- if ( bsize < noffset )
- *bptr = ( noffset - bsize - SSIZE ) | FREE ;
- Header->BytesUsed = noffset ;
- AllocationTable [NEntry-1].Size = noffset ;
- } ;
- } ;
- } ;
- }
- #endif
- #endif
-